<?php
/**
 * 博主信息控件 blogfeaturecontroller.php
 * 参数简介：
 * queryId 查询使用ID 与type关联使用
 * type 类型  1表示根据bloggerId获取博主信息 2表示根据blogId获取博主信息
 * limit 条数
 * Create on 2015-09-11
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\channel\blog;
class BlogFeatureController extends \haibao\cms\business\control\pc\channel\blog\BlogController{
	
	const FEATURE_LIST_BY_BLOGGER_ID = 1;
	const FEATURE_LIST_BY_BLOG_ID = 2;
	const FEATURE_LIST_BY_CATE_ID = 3;
	const FEATURE_LIST_BY_TAG_ID = 4;
	
	const FEATURE_LOCATION_CATE = 1;
	const FEATURE_LOCATION_USER = 2;
	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	/**
	 * 获取模版内容
	 * @param : String $content
	 */
	public function displayTemplateHtml(){
	
		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		$bloggerInfo = array();
		$bloggerId = $cateId = 0;
		
		if($controlData['manual']){
			$type = isset($controlData['manual']['type'])?$controlData['manual']['type']:self::FEATURE_LIST_BY_CATE_ID;
			$location = isset($controlData['manual']['location'])?$controlData['manual']['location']:self::FEATURE_LOCATION_CATE;
			if($location == self::FEATURE_LOCATION_CATE){
				$locationName = '_cate';
			}elseif ($location == self::FEATURE_LOCATION_USER){
				$locationName = '_user';
			}else{
				$locationName = '';
			}
			$this->assign('locationName',$locationName);
			switch($type){
				case self::FEATURE_LIST_BY_BLOGGER_ID:
					$bloggerId = $controlData['manual']['queryId'];
					$bloggerInfo = $this->getBloggerInfoById($bloggerId,false);
					if($bloggerInfo){
						$cateId = $bloggerInfo['cate_id'];
					}
					break;

				case self::FEATURE_LIST_BY_BLOG_ID:
					$blogInfo = $this->getBlogInfoByBlogId($controlData['manual']['queryId']);
					if($blogInfo){
						$bloggerId = $blogInfo['uid'];
						$bloggerInfo = $this->getBloggerInfoById($bloggerId,false);
						$cateId = $bloggerInfo['cate_id'];
					}
					break;

				case self::FEATURE_LIST_BY_CATE_ID:
					$cateId = $controlData['manual']['queryId'];
					break;
				case self::FEATURE_LIST_BY_TAG_ID:
					list($cateInfo,$cateId) = self::getCateInfo($this->getParameter(self::$SITE_CHANNEL_TAG),true);
					break;
				default:
					break;
			}

			if($cateId){
				$this->getBlogFeatureList($controlData['manual'],$cateId);
			}
		}
		$path = $this->generateHtmlPath(__CLASS__);
		$this->generateHtml($path,$content);
		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}
	
	
	/**
	 * 获取专题
	 */
	private function getBlogFeatureList($dataCondition,$cateId){
		
		$featureList = array();
		$cateInfo = self::getCateInfo($cateId);
		$featureClassId = $cateInfo['featureClassId'];
		$features = \haibao\cms\business\control\FeatureController::getFeatureByChannel($featureClassId,$dataCondition['limit']);
		foreach($features as $feature){
			$feature->Pic = $feature->Image->Filename;
			array_push($featureList,$feature);
		}
		$this->assign('featureList',$featureList);
		
	}
	
}